package com.open.cinema.system.config;

import com.open.cinema.system.model.UserInfo;
import com.open.cinema.system.service.UserService;
import org.apache.shiro.authc.*;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;
import org.springframework.beans.factory.annotation.Autowired;

public class MyShiroRealm extends AuthorizingRealm {

    @Autowired
    private UserService userService;
    @Override
    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
        /*SimpleAuthorizationInfo authorizationInfo=new SimpleAuthorizationInfo();
        UserInfo userInfo= (UserInfo) principalCollection.getPrimaryPrincipal();*/

        return null;
    }
    /*主要是用来进行身份认证的，也就是说验证用户输入的账号和密码是否正确。*/
    @Override
    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
        UsernamePasswordToken user=(UsernamePasswordToken)authenticationToken;


        //根据用户名去查询用户信息
        UserInfo userInfo = userService.finUserByUserCode(user.getUsername());
        String pwd="111111";


        SimpleAuthenticationInfo authenticationInfo=new SimpleAuthenticationInfo(userInfo,pwd,getName());


        return authenticationInfo;
    }
}
